package com.novel.test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

public class TraverseFileintoOne {

	public static void main(String[] args) {
		String path = "E:\\aaa";		//要遍历的路径
		File file = new File(path);		//获取其file对象
		File[] fs = file.listFiles();	//遍历path下的文件和目录，放在File数组中
		for(File f:fs){					//遍历File[]数组
			if(!f.isDirectory())		//若非目录(即文件)，则打印
			{
				
				System.out.print("开始");
				System.out.println(f);
				importIntoOne(f);
				System.out.println("结束");
				System.out.println();
			}
		}
	}
	public static void importIntoOne(File file){
         BufferedReader reader = null;  
         File f = new File("E:\\bbb.txt");
         try { 
	         FileWriter fw = new FileWriter(f, true);
	         PrintWriter pw = new PrintWriter(fw);
	         reader = new BufferedReader(new FileReader(file));  
	         String tempString = null;  
	         // 一次读入一行，直到读入null为文件结束  
            
	         while ((tempString = reader.readLine()) != null) {  
	        	 pw.println(tempString);
	        	 pw.flush();
	         }
	         pw.flush();
	         pw.close();
	         fw.close();
	         reader.close();  
	      } catch (IOException e) {  
	         e.printStackTrace();  
	      }  
         
	}

}
